/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewCRTemplate.java
 *
 * Created on Sep 23, 2009, 9:53:47 AM
 */

package com.sabre.hd.gui;

import com.sabre.hd.easysr.Facade;
import com.sabre.hd.easysr.entities.ChangeRequest;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author SG0203703
 */
public class NewWorkflow extends javax.swing.JFrame {

    /** Creates new form NewCRTemplate */
    public NewWorkflow() {
        initComponents();
        //loadCRTemplates();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    pnlActions = new javax.swing.JPanel();
    btnClose = new javax.swing.JButton();
    btnNew = new javax.swing.JButton();
    btnLoad = new javax.swing.JButton();
    btnSave = new javax.swing.JButton();
    jButton1 = new javax.swing.JButton();
    pnlCRList = new javax.swing.JPanel();
    scrCRList = new javax.swing.JScrollPane();
    templatesList = new DefaultListModel();
    lstCRTemplates = new javax.swing.JList(templatesList);
    jComboBox1 = new javax.swing.JComboBox();
    jLabel1 = new javax.swing.JLabel();
    scrCRList1 = new javax.swing.JScrollPane();
    templatesList = new DefaultListModel();
    lstWorkflowItems = new javax.swing.JList(templatesList);

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/sabre/hd/resources/images/cancel.png"))); // NOI18N
    btnClose.setText("Close");

    btnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/sabre/hd/resources/images/page.png"))); // NOI18N
    btnNew.setText("New");

    btnLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/sabre/hd/resources/images/folder_add.png"))); // NOI18N
    btnLoad.setText("Load");
    btnLoad.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnLoadActionPerformed(evt);
      }
    });

    btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/sabre/hd/resources/images/disk.png"))); // NOI18N
    btnSave.setText("Save");
    btnSave.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnSaveActionPerformed(evt);
      }
    });

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/sabre/hd/resources/images/page_code.png"))); // NOI18N
    jButton1.setText("Execute Workflow");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout pnlActionsLayout = new javax.swing.GroupLayout(pnlActions);
    pnlActions.setLayout(pnlActionsLayout);
    pnlActionsLayout.setHorizontalGroup(
      pnlActionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(pnlActionsLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(pnlActionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(btnSave, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
          .addComponent(btnLoad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
          .addComponent(btnNew, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
          .addComponent(btnClose, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
          .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
        .addContainerGap())
    );
    pnlActionsLayout.setVerticalGroup(
      pnlActionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(pnlActionsLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(btnSave)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(btnLoad)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(btnNew)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(btnClose)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jButton1)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    lstCRTemplates.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    scrCRList.setViewportView(lstCRTemplates);

    javax.swing.GroupLayout pnlCRListLayout = new javax.swing.GroupLayout(pnlCRList);
    pnlCRList.setLayout(pnlCRListLayout);
    pnlCRListLayout.setHorizontalGroup(
      pnlCRListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(pnlCRListLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(scrCRList, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    pnlCRListLayout.setVerticalGroup(
      pnlCRListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(pnlCRListLayout.createSequentialGroup()
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addComponent(scrCRList, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AirMax GUI Installation", "AirMax FileSystem Creation", "Cargomax AC new release Installation", "Cargmax GUI patch", "CargoSpot libraries Update" }));
    jComboBox1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jComboBox1ActionPerformed(evt);
      }
    });

    jLabel1.setFont(new java.awt.Font("Verdana", 2, 18));
    jLabel1.setText("Select a Workflow");

    lstWorkflowItems.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    scrCRList1.setViewportView(lstWorkflowItems);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jLabel1))
          .addComponent(scrCRList1, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
          .addComponent(pnlCRList, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addComponent(pnlActions, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGap(25, 25, 25)
            .addComponent(pnlActions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(pnlCRList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(layout.createSequentialGroup()
            .addGap(29, 29, 29)
            .addComponent(jLabel1)
            .addGap(18, 18, 18)
            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(scrCRList1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
      if (saveSRTemplate()) {
        JOptionPane.showMessageDialog(this,
                "Your SR Template was succesfully Saved!",
                "Success",
                JOptionPane.INFORMATION_MESSAGE);
      } else {
        JOptionPane.showMessageDialog(this,
                "Your SR Template could not be saved!",
                "Error",
                JOptionPane.ERROR_MESSAGE);
      }
}//GEN-LAST:event_btnSaveActionPerformed

    private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnLoadActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
//      if (lstCRTemplates.getSelectedIndex()==-1) {
//        JOptionPane.showMessageDialog(this,
//          "Please select a CR Template first!",
//          "Error",
//          JOptionPane.WARNING_MESSAGE);
//      }
//      else {
        Facade.executeSeleniumWorkflow();
//      }
      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
       if (jComboBox1.getSelectedIndex() == 2 ) {
            DefaultListModel dlm = new DefaultListModel();
            dlm.addElement((Object) "SR : EMG   schema change AC cargomax on Cert");
            dlm.addElement((Object) "CR : Deploy cargomax GUI for AC");
            lstWorkflowItems.setModel(dlm);
        }
       else {
            DefaultListModel dlm = new DefaultListModel();
            dlm.addElement((Object) "--No Items in Workflow--");
            lstWorkflowItems.setModel(dlm);

       }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewWorkflow().setVisible(true);
            }
        });
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton btnClose;
  private javax.swing.JButton btnLoad;
  private javax.swing.JButton btnNew;
  private javax.swing.JButton btnSave;
  private javax.swing.JButton jButton1;
  private javax.swing.JComboBox jComboBox1;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JList lstCRTemplates;
  private javax.swing.JList lstWorkflowItems;
  private javax.swing.JPanel pnlActions;
  private javax.swing.JPanel pnlCRList;
  private javax.swing.JScrollPane scrCRList;
  private javax.swing.JScrollPane scrCRList1;
  // End of variables declaration//GEN-END:variables

  private DefaultListModel templatesList;

  private boolean saveSRTemplate() {
    return true;
  }

  private void loadCRTemplates() {
    templatesList.clear();
    ArrayList<ChangeRequest> allChangeRequests = Facade.getAllChangeRequests();
    for (ChangeRequest aChangeRequest : allChangeRequests) {
      templatesList.addElement(aChangeRequest);
    }
  }

}
